//=============================================================================
// SentinelProjectile
//=============================================================================
class SentinelProjectile extends TFProjectile;

var class<xEmitter> SparkClass;
var Texture TrailTexture;
var xEmitter Trail;

simulated function Destroyed()
{
	if(Trail != None)
	{
		Trail.Destroy();
	}

	Super.Destroyed();
}

simulated function PostBeginPlay()
{
	local Rotator R;

	Super.PostBeginPlay();

	if(EffectIsRelevant(vect(0,0,0),false))
	{
		Trail = Spawn(class'LinkProjEffect',self);

		if(Trail != None)
		{
			Trail.Skins[0] = TrailTexture;
			Trail.mOwnerVelocityFactor = 0.5;
		}
	}

	Velocity = Vector(Rotation) * Speed;

	R = Rotation;
	R.Roll = Rand(65536);
	SetRotation(R);

	if(Level.bDropDetail)
	{
		bDynamicLight = false;
		LightType = LT_None;
	}
}

simulated function PostNetBeginPlay()
{
	if(Level.bDropDetail || Level.DetailMode == DM_Low)
		LightType = LT_None;
}

simulated function Explode(vector HitLocation, vector HitNormal)
{
	if(EffectIsRelevant(Location,false))
		Spawn(SparkClass,,, HitLocation, rotator(HitNormal));

	PlaySound(Sound'WeaponSounds.BioRifle.BioRifleGoo2');
	Destroy();
}

simulated function ProcessTouch (Actor Other, vector HitLocation)
{
	local Vector X, RefNormal, RefDir;

	if(owner!=none &&((Other.IsA('ShieldSphere') && ShieldSphere(Other).Shield.Sentinel == sentinel(owner)) || (Other.IsA('BigShieldSphere') && BigShieldSphere(Other).Shield.myteam == sentinel(owner).myteam) || Other == owner))
		return;

	if(Other.IsA('xPawn') && xPawn(Other).CheckReflect(HitLocation, RefNormal, Damage*0.25))
	{
		if(Role == ROLE_Authority)
		{
			X = Normal(Velocity);
			RefDir = X - 2.0*RefNormal*(X dot RefNormal);
			Spawn(Class, Other,, HitLocation+RefDir*20, Rotator(RefDir));
		}

		Destroy();
	}
	else if(!Other.IsA('Projectile') || Other.bProjTarget)
	{
		if(Role == ROLE_Authority)
		{
			//Encourage enemy Sentinels to fight back.
			if(Owner!=none && Other.IsA('Sentinel') && Sentinel(Other).Controller != None)
				Sentinel(Other).Controller.NotifyTakeHit(Pawn(Owner), HitLocation, Damage, MyDamageType, MomentumTransfer * Normal(Velocity));

			Other.TakeDamage(Damage, Instigator, HitLocation, MomentumTransfer * Normal(Velocity), MyDamageType);
		}

		Explode(HitLocation, vect(0,0,1));
	}
}

defaultproperties
{
     SparkClass=Class'taskforces.SentinelProjSparks'
     TrailTexture=Texture'XEffectMat.Link.link_muz_blue'
     Speed=2000.000000
     Damage=40.000000
     MomentumTransfer=30000.000000
     MyDamageType=Class'taskforces.DamTypeSentinel'
     ExplosionDecal=Class'XEffects.LinkBoltScorch'
     LightType=LT_Steady
     LightEffect=LE_QuadraticNonIncidence
     LightHue=150
     LightSaturation=100
     LightBrightness=150.000000
     LightRadius=4.000000
     DrawType=DT_StaticMesh
     StaticMesh=StaticMesh'WeaponStaticMesh.LinkProjectile'
     bDynamicLight=True
     AmbientSound=Sound'WeaponSounds.LinkGun.BLinkGunBeam2'
     LifeSpan=4.500000
     DrawScale=1.500000
     DrawScale3D=(X=2.550000,Y=1.700000,Z=1.700000)
     PrePivot=(X=10.000000)
     Skins(0)=FinalBlend'TFMedia.Projectiles.SentinelProjFB'
     AmbientGlow=217
     Style=STY_Additive
     SoundVolume=255
     SoundRadius=50.000000
     bFixedRotationDir=True
     RotationRate=(Roll=80000)
}
